﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using LDTB.Service;

namespace LDTB
{
    public partial class VillageAdd : Form
    {
        LDTBDataDataContext ds = DataService.DB;
        public VillageAdd()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //lay ve gia tri vua nhap

            string name = txtName.Text.Trim();

            int wardid = int.Parse(this.ddlWard.SelectedValue.ToString());

            //kiem tra da ton tai chua



            //insert du lieu

            var village = new Village {VillageName=name,WardID=wardid};
            ds.Villages.InsertOnSubmit(village);
            ds.SubmitChanges();

            if (village.VillageID != 0)
            {

                MessageBox.Show("Thêm thành công");
            }
            else {

                MessageBox.Show("Thêm thất bại");
            
            }

        }

        private void VillageAdd_Load(object sender, EventArgs e)
        {
            List<Ward> list = new List<Ward>();
           
            list.AddRange(from w in ds.Wards select w);

            ddlWard.DataSource = list;
            ddlWard.DisplayMember = "WardName";
            ddlWard.ValueMember = "ID";

        }
    }
}
